Lua['move_motor'] = function (block) {
  let speed_left;
  let speed_right;
  if (block.getField('SPEEDLEFT')) {
    // Internal number.
    speed_left = String(Number(block.getFieldValue('SPEEDLEFT')));
  } else {
    // External number.
    speed_left = Lua.valueToCode(block, 'SPEEDLEFT', Lua.ORDER_NONE) || '0';
  }
  if (block.getField('SPEEDRIGHT')) {
    // Internal number.
    speed_right = String(Number(block.getFieldValue('SPEEDRIGHT')));
  } else {
    // External number.
    speed_right = Lua.valueToCode(block, 'SPEEDRIGHT', Lua.ORDER_NONE) || '0';
  }
  const code = `motor(${speed_left},${speed_right})\n`;
  return code
};

Lua['move_arm'] = function (block) {
  let main_arm;
  let auxiliary_arm_1;
  let auxiliary_arm_2;
  let auxiliary_arm_3;

  if (block.getField('MAINARM')) {
    // Internal number.
    main_arm = String(Number(block.getFieldValue('MAINARM')));
  } else {
    // External number.
    main_arm = Lua.valueToCode(block, 'MAINARM', Lua.ORDER_NONE) || '0';
  }

  if (block.getField('AUXILIARYARM1')) {
    // Internal number.
    auxiliary_arm_1 = String(Number(block.getFieldValue('AUXILIARYARM1')));
  } else {
    // External number.
    auxiliary_arm_1 = Lua.valueToCode(block, 'AUXILIARYARM1', Lua.ORDER_NONE) || '0';
  }

  if (block.getField('AUXILIARYARM2')) {
    // Internal number.
    auxiliary_arm_2 = String(Number(block.getFieldValue('AUXILIARYARM2')));
  } else {
    // External number.
    auxiliary_arm_2 = Lua.valueToCode(block, 'AUXILIARYARM2', Lua.ORDER_NONE) || '0';
  }

  if (block.getField('AUXILIARYARM3')) {
    // Internal number.
    auxiliary_arm_3 = String(Number(block.getFieldValue('AUXILIARYARM3')));
  } else {
    // External number.
    auxiliary_arm_3 = Lua.valueToCode(block, 'AUXILIARYARM3', Lua.ORDER_NONE) || '0';
  }

  const code = `rotate_arm(${main_arm}, ${auxiliary_arm_1}, ${auxiliary_arm_2}, ${auxiliary_arm_3})\n`;
  return code
}

Lua['move_motor_stop'] = function (block) {
  const code = `stopmotor()\n`;
  return code
};
